package com.atguigu.gulimall.search.thread;

import java.util.concurrent.*;
import java.util.function.Supplier;

/**
 * @author: jianPing
 * @date: 2022/3/17 15:18
 * @description:
 */
public class ThreadTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
        //创建线程池
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5,
                50,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(50),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        System.out.println("run start......");
        //使用线程池执行任务
//        poolExecutor.execute(() -> System.out.println("无返回值方法运行....."));
//        Future<?> future = poolExecutor.submit(() -> {
//            Integer i = 10 / 2;
//            System.out.println("result: "+ i);
//        });
//        Object o = future.get();
//        System.out.println("o: "+o);

//        Future<Integer> future = poolExecutor.submit(() -> {
//            int i = 10 / 2;
//            System.out.println("callable..");
//            return i;
//        });
//        System.out.println(future.get(10, TimeUnit.SECONDS));

//        Future<Integer> future = poolExecutor.submit(() -> {
//            int i = 10 / 2;
//            System.out.println("runable....." + i);
//        }, 20);
//        System.out.println(future.get());

//        CompletableFuture<Object> completableFuture = new CompletableFuture<>();
//        CompletableFuture.runAsync(() -> System.out.println("runable......"));

//        System.out.println(CompletableFuture.supplyAsync((Supplier<Object>) () -> {
//            int i = 10 / 2;
//            return i;
//        }, poolExecutor).);
//        System.out.println("run end......");
    }
}
